package com.liuche.book.auth.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuche.book.auth.dao.mapper.RoleMapper;
import com.liuche.book.auth.model.entity.Role;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author：liuche
 * @Date：2024年07月07日 08:58
 * @Description：
 */
@Repository
public class RoleDao extends ServiceImpl<RoleMapper, Role> {
    /**
     * 查询权限信息通过角色 id
     * @param commonUserRoleId 角色id
     * @return 权限信息
     */
    public Role queryRoleInfo(Long commonUserRoleId) {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Role::getId, commonUserRoleId);

        return getOne(queryWrapper);
    }


    /**
     * 获取所有可用的权限信息
     * @return
     */
    public List<Role> queryEnabledList() {
        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Role::getIsDeleted, 0);

        return list(queryWrapper);
    }
}
